#pragma once

#include "stdafx.h"
#include "scene/drawable.h"

namespace natrium {
	namespace scene {
		//wraps camera projection and position/orientation; can be rendered, possibly to show frustums from another perspective
		//** lookAt-style state
		class Frustum:
			public Drawable
		{
		public:
			enum eProjection {
				PERSPECTIVE,
				ORTHOGRAPHIC
			};

			Frustum(eProjection type = PERSPECTIVE);

			void lookAt(const glm::vec3& origin, const glm::vec3& at, const glm::vec3& up); //the 'at' vector is also known as 'center'
		
			void setOrthoBounds(float xMin, float xMax, float yMin, float yMax, float zMin, float zMax);
			void setPerspective(float fovy, float aspect, float zNear, float zFar);

			void enclose(const Frustum& f);

			glm::mat4 getViewMatrix() const;
			glm::mat4 getProjectionMatrix() const;
			glm::vec3 getOrigin() const;
			glm::vec3 getCenter() const; //returns the actual center of the view frustum

			void listInfo() const;

			virtual void render() const override;
		
		private:
			eProjection mProjectionType;
		
			glm::vec3 mPosition;
			glm::vec3 mUp;
			glm::vec3 mCenter; 

			float mZNear;
			float mZFar;

			float mXMin;
			float mXMax;
			float mYMin;
			float mYMax;

			float mFOVy; //in degrees
			float mAspect;

			glm::mat4 mViewMatrix;
			glm::mat4 mProjectionMatrix;

			GLuint mHandle[2]; //the handles for the vertex and index buffers
		};
	}
}